﻿using System.Windows;
using System.Windows.Input;

namespace MSAP.Framework
{
    public class BindableRelayCommand : DependencyObject
    {
        public static RelayCommand GetCommand(DependencyObject obj)
        {
            return (RelayCommand)obj.GetValue(CommandProperty);
        }

        public static void SetCommand(DependencyObject obj, RelayCommand value)
        {
            obj.SetValue(CommandProperty, value);
        }

        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.RegisterAttached("Command", typeof(RelayCommand), typeof(BindableRelayCommand),
            new FrameworkPropertyMetadata(CommandChanged));

        private static void CommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //InputBinding inputBinding = d as InputBinding;

            FrameworkElement fe = d as FrameworkElement;
            RelayCommand command = e.NewValue as RelayCommand;

            InputBinding inputBinding = new InputBinding(command, new MouseGesture(MouseAction.LeftDoubleClick));
            fe.InputBindings.Add(inputBinding);  
        }
    }
}
